import request from '@/utils/request'

const userId = '0000'
const priceList = [49900, 59900, 69900, 79900]
export function getGoods() {
  const timestamp = Math.floor(Date.now() / 1000)
  const price = priceList[timestamp % 4]
  request.get(`/order?price=${price}&userId=${userId}&type=1`).then(resp => {
    const data = {
      'pddOrderId': Math.floor(Date.now()),
      'goodsId': resp.data.goods_id,
      'payType': 'alipay',
      'tag': resp.data.tag,
      'fromPlatform': 'pdd',
      'ctime': timestamp,
      'group_order_id': Math.floor(Date.now()),
      'total': resp.data.price
    }
    setTimeout(() => {
      request.post('/order', data)
    }, randomNum(10 * 1000, 15 * 1000))
  })
}

// 生成从minNum到maxNum的随机数
function randomNum(minNum, maxNum) {
  switch (arguments.length) {
    case 1:
      return parseInt(Math.random() * minNum + 1, 10)
    case 2:
      return parseInt(Math.random() * (maxNum - minNum + 1) + minNum, 10)
    default:
      return 0
  }
}
